package com.jaj.common;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.io.FileUtils;

/**
 * Created by chm on 2018/1/25.
 *
 * @author j aj
 */
public class MyFileUtils {

    /**
     * 根据给定目录递归获取所有的java文件，并组装以逗号隔开返回
     *
     * @param path
     * @return
     */
    public static List<String> getJavaFileList(String path) {
        File directory = new File(path);
        List<String> result = new ArrayList<>();
        Collection<File> fileCollection = FileUtils.listFiles(directory, null, true);
        for (File file : fileCollection) {
            if (file.isFile() && file.getName().endsWith(".java")) {
                result.add(file.getPath());
            }
        }
        return result;
    }

    public static void main(String[] args) {
        String strDirectory = "D:\\sonlidev\\FeedBackSystem\\master\\witparking-feedback.interfaces\\src\\main\\java\\org\\witparking\\feedback\\interfaces";
        List<String> aa = getJavaFileList(strDirectory);
        System.err.println(aa);
    }
}
